package org.infodavid.common.ejb.components;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.PostLoad;
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import org.infodavid.common.impl.model.PhoneImpl;

/**
 * The Class PhoneComponent.
 */
@Embeddable
public class PhoneComponent extends PhoneImpl {

  /** serialVersionUID. */
  private static final long serialVersionUID = 8503774195166888625L;

  /**
   * The Constructor.
   * @throws Exception the exception
   */
  protected PhoneComponent() throws Exception {
    super();
  }

  /*
   * (non-Javadoc)
   * @see org.infodavid.common.model.entities.impl.PhoneImpl#getType()
   */
  @Override
  @Enumerated(EnumType.STRING)
  @Column(name = "type", nullable = true, length = 16)
  public EPhoneType getType() {
    return super.getType();
  }

  /*
   * (non-Javadoc)
   * @see org.infodavid.common.model.entities.impl.PhoneImpl#getValue()
   */
  @Override
  @Column(name = "value", nullable = false, length = 32)
  public String getValue() {
    return super.getValue();
  }

  /**
   * Post store.
   */
  @PostLoad
  @PostUpdate
  @PostPersist
  protected void postStore() {
    if (getType() == null) {
      setType(EPhoneType.UNDEFINED);
    }
  }

  /**
   * Pre store.
   */
  @PreUpdate
  @PrePersist
  protected void preStore() {
    if (getType() == null) {
      setType(EPhoneType.UNDEFINED);
    }
  }
}
